package com.yl.chainStore.entity.customer

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.pojo.vo.customer.CustomerLeftJoinInfo
import com.yl.common.annotation.NoArg
import com.yl.common.getContext
import java.util.*

/**
 * <p>
 *
 * </p>
 *
 * @author cxw
 * @since 2021-12-01
 */
@NoArg
@TableName("customer_info_associated")
data class CustomerInfoAssociated(

	/**
	 * id
	 */
	@TableId(value = "id", type = IdType.AUTO)
	var id: Long,

	/**
	 * 患者id
	 */
	@TableField("customer_id")
	var customerId: Long,

	/**
	 * 关联患者id
	 */
	@TableField("associated_customer_id")
	var associatedCustomerId: Long,

	/**
	 * 关系customer->associated_customer
	 */
	@TableField("associated_name")
	var associatedName: String = "",

	/**
	 * 添加用户
	 */
	@TableField("create_user_id")
	var createUserId: Long = getContext().userId,

	/**
	 * 创建时间
	 */
	@TableField("create_time")
	var createTime: Date = Date(),

	/**
	 * 关系associated_customer->customer
	 */
	@TableField("associated_back_name")
	var associatedBackName: String = associatedName,


	/**
	 * 通过其中一个患者获取的另一个患者的称呼
	 */
	@TableField(exist = false)
	var associatedById:String?=null

	):CustomerLeftJoinInfo(){
	var associatedNameShow:List<String>?
		get() {
			val split = associatedName.split(",")
			val re = mutableListOf<String>()
			for (s in split) {
				if (s.isEmpty()) {
					continue
				}
				re.add(s)
			}
			return re
		}
		set(value) {
			val str = StringBuffer()
			if (!value.isNullOrEmpty()) {
				for (i in value) {
					str.append("$i,")
				}
			}
			val toString = str.toString()
			if(toString.isNotEmpty()){
				associatedName = toString.substring(0,toString.length-1)
			}

		}
	}

